package vip.liux.contracts.security;


import com.fasterxml.jackson.annotation.JsonUnwrapped;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class UserInfo extends User implements UserDetailsInfo, Serializable {

    private final String id;
    private final String name;
    private final String surName;
    private final String phoneNumber;
    private final String email;
    private final boolean phoneNumberConfirmed;
    private final boolean emailConfirmed;
    private final Set<String> roles;

    @JsonUnwrapped
    private final Map<String, Object> attributes = new HashMap<>();

    public UserInfo(String id, String name, String surName, String phoneNumber, String email,
                    boolean phoneNumberConfirmed, boolean emailConfirmed,
                    Set<String> roles, String username, String password, boolean enabled, boolean accountNonLocked,
                    Collection<? extends GrantedAuthority> authorities) {
        super(username, password, enabled, true, true, accountNonLocked, authorities);
        this.id = id;
        this.name = name;
        this.surName = surName;
        this.phoneNumber = phoneNumber;
        this.email = email;
        this.phoneNumberConfirmed = phoneNumberConfirmed;
        this.emailConfirmed = emailConfirmed;
        this.roles = roles;
    }

    public UserInfo(String username) {
        super(username, "", true, true, true, true, Set.of());
        this.id = "";
        this.name = "";
        this.surName = "";
        this.phoneNumber = "";
        this.email = "";
        this.phoneNumberConfirmed = false;
        this.emailConfirmed = false;
        this.roles = Set.of();
    }

    @Override
    public String getId() {
        return this.id;
    }

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public String getSurName() {
        return this.surName;
    }

    @Override
    public String getPhoneNumber() {
        return this.phoneNumber;
    }

    @Override
    public String getEmail() {
        return this.email;
    }

    @Override
    public boolean isPhoneNumberConfirmed() {
        return this.phoneNumberConfirmed;
    }

    @Override
    public boolean isEmailConfirmed() {
        return this.emailConfirmed;
    }

    @Override
    public Set<String> getRoles() {
        return this.roles;
    }

    @Override
    public Map<String, Object> getAttributes() {
        return attributes;
    }


}